package com.admin.business.portalWebsite.venusJobDeliver;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 用户投递表
 * @create: 2023-11-21 14:18:29
 **/
@Service("venusJobDeliverService")
@Slf4j
public class VenusJobDeliverService{

    @Resource
    VenusJobDeliverDao venusJobDeliverDao;

    /**
     * 添加用户投递表,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户ID
     *                   - job_id:职位ID
     *                   - create_time:投递时间
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return addVenusJobDeliver(CDO cdoRequest) {
        venusJobDeliverDao.addVenusJobDeliver(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新用户投递表数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户ID
     *                   - job_id:职位ID
     *                   - create_time:投递时间
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return updateVenusJobDeliverById(CDO cdoRequest) {
        venusJobDeliverDao.updateVenusJobDeliverById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除用户投递表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusJobDeliverById(CDO cdoRequest){
        int count = venusJobDeliverDao.deleteVenusJobDeliverById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除用户投递表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return deleteVenusJobDeliver(CDO cdoRequest) {
        int count = venusJobDeliverDao.deleteVenusJobDeliver(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取用户投递表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusJobDeliverById(CDO cdoRequest) {
        CDO cdoMapperResult = venusJobDeliverDao.getVenusJobDeliverById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取用户投递表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusJobDeliverListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusJobDeliverDao.getVenusJobDeliverListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusJobDeliverDao.getVenusJobDeliverCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取用户投递表数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-11-21 14:18:29
     */
    @OpenApi
    public Return getVenusJobDeliverListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusJobDeliverDao.getVenusJobDeliverListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusJobDeliverDao.getVenusJobDeliverCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
